﻿using System;
using System.Windows.Forms;
using bbtpClient.Entities;
using bbtpClient.Controllers;

namespace bbtpClient
{
    public partial class SetTransportCompanyOrderOrReturnForm : Form
    {
        OrderType ordersType;

        public SetTransportCompanyOrderOrReturnForm(OrderType type, TransportCompanyHead[] companies, OrderHead[] orders)
        {
            InitializeComponent();
            label_UserName.Text = UserInfo.Name;

            this.ordersType = type;
            if (ordersType.Equals(OrderType.ORDINARY))
            {
                this.Text = "Set Transport Company for Order";
                message_label.Text = "Установите транспортную компанию для заказа";
            }
            if (ordersType.Equals(OrderType.FOR_RETURN))
            {
                this.Text = "Set Transport Company for Return";
                message_label.Text = "Установите транспортную компанию для возврата заказа";
            }
            orders_listBox.Items.AddRange(orders);
            companies_listBox.Items.AddRange(companies);
        }

        private void setCompanyToOrder_button_Click(object sender, EventArgs e)
        {
            int selectedCompanyIndex = companies_listBox.SelectedIndex;
            TransportCompanyHead selectedCompany = (TransportCompanyHead)companies_listBox.Items[selectedCompanyIndex];

            int selectedOrderIndex = orders_listBox.SelectedIndex;
            OrderHead selectedOrder = (OrderHead)orders_listBox.Items[selectedOrderIndex];

            TransportManagerController.SetTransportCompanyForOrder(selectedCompany.id, selectedOrder.id, this);

           // list1Update();
        }

        public void DeleteSelectedOrderFromList()
        {
            int selectedOrderIndex = orders_listBox.SelectedIndex;
            orders_listBox.Items.RemoveAt(selectedOrderIndex);
        }

        private void exit_button_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}